package org.devknights.android.moneyeye.core.adapters;


import java.util.List;
import java.util.Map;

import org.devknights.android.R;
import org.devknights.android.andlib.components.TextProgressBar;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
 

public class ListViewAdapter extends BaseAdapter
{
    public List<Map<String,String>> list;
    Activity activity;
 
    public ListViewAdapter(Activity activity, List<Map<String,String>> list) {
        super();
        this.activity = activity;
        this.list = list;
    }
 
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }
 
    public List<Map<String, String>> getList() {
		return list;
	}

	public void setList(List<Map<String, String>> list) {
		this.list = list;
	}

	@Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
 
    private class ViewHolder {
           TextView txtFirst;
           //TextView txtSecond;
           TextProgressBar pbar;
           
      }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
 
        // TODO Auto-generated method stub
                ViewHolder holder;
                LayoutInflater inflater =  activity.getLayoutInflater();
 
                if (null == convertView)
                {
                    convertView = inflater.inflate(R.layout.listview_template, null);
                    holder = new ViewHolder();
                    holder.txtFirst = (TextView) convertView.findViewById(R.id.FirstText);                    
                    holder.pbar = (TextProgressBar) convertView.findViewById(R.id.progid);
                    convertView.setTag(holder);
                }
                else
                {
                    holder = (ViewHolder) convertView.getTag();
                }
 
                Map<String,String> map = list.get(position);
                holder.txtFirst.setText((String) map.get("Bank"));                
                holder.pbar.setMax(Integer.parseInt((String) map.get("max")));
                holder.pbar.setProgress(Integer.parseInt((String) map.get("amount"))); 
                holder.pbar.setText((String) map.get("amount") +"/"+(String) map.get("max"));
 
            return convertView;
    }
 
}